<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>ActionController::MimeResponds::ClassMethods</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/github.css" type="text/css" media="screen" />
<script src="../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Module</span> 
            ActionController::MimeResponds::ClassMethods 
            
        </h1>
        <ul class="files">
            
            <li><a href="../../../files/actionpack/lib/action_controller/metal/mime_responds_rb.html">actionpack/lib/action_controller/metal/mime_responds.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  


  


  
  


  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>C</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="ClassMethods.html#method-i-clear_respond_to">clear_respond_to</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>R</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="ClassMethods.html#method-i-respond_to">respond_to</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  



  

    

    

    


    


    <!-- Methods -->
        
      <div class="sectiontitle">Instance Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-clear_respond_to">
            
              <b>clear_respond_to</b>()
            
            <a href="ClassMethods.html#method-i-clear_respond_to" name="method-i-clear_respond_to" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Clear all mime types in <code>respond_to</code>.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-clear_respond_to_source')" id="l_method-i-clear_respond_to_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/149e3cd376caa23cf4d8c4b711b95e157186fc94/actionpack/lib/action_controller/metal/mime_responds.rb#L55" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-clear_respond_to_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_controller/metal/mime_responds.rb, line 55</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">clear_respond_to</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">mimes_for_respond_to</span> = <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">freeze</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-respond_to">
            
              <b>respond_to</b>(*mimes)
            
            <a href="ClassMethods.html#method-i-respond_to" name="method-i-respond_to" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Defines mime types that are rendered by default when invoking
<code>respond_with</code>.</p>

<pre>respond_to :html, :xml, :json</pre>

<p>Specifies that all actions in the controller respond to requests for
<code>:html</code>, <code>:xml</code> and <code>:json</code>.</p>

<p>To specify on per-action basis, use <code>:only</code> and
<code>:except</code> with an array of actions or a single action:</p>

<pre>respond_to :html
respond_to :xml, :json, except: [ :edit ]</pre>

<p>This specifies that all actions respond to <code>:html</code> and all
actions except <code>:edit</code> respond to <code>:xml</code> and
<code>:json</code>.</p>

<pre>respond_to :json, only: :create</pre>

<p>This specifies that the <code>:create</code> action and no other responds
to <code>:json</code>.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-respond_to_source')" id="l_method-i-respond_to_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/149e3cd376caa23cf4d8c4b711b95e157186fc94/actionpack/lib/action_controller/metal/mime_responds.rb#L37" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-respond_to_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_controller/metal/mime_responds.rb, line 37</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">respond_to</span>(*<span class="ruby-identifier">mimes</span>)
  <span class="ruby-identifier">options</span> = <span class="ruby-identifier">mimes</span>.<span class="ruby-identifier">extract_options!</span>

  <span class="ruby-identifier">only_actions</span>   = <span class="ruby-constant">Array</span>(<span class="ruby-identifier">options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:only</span>)).<span class="ruby-identifier">map</span>(&amp;<span class="ruby-value">:to_s</span>)
  <span class="ruby-identifier">except_actions</span> = <span class="ruby-constant">Array</span>(<span class="ruby-identifier">options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:except</span>)).<span class="ruby-identifier">map</span>(&amp;<span class="ruby-value">:to_s</span>)

  <span class="ruby-identifier">new</span> = <span class="ruby-identifier">mimes_for_respond_to</span>.<span class="ruby-identifier">dup</span>
  <span class="ruby-identifier">mimes</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">mime</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">mime</span> = <span class="ruby-identifier">mime</span>.<span class="ruby-identifier">to_sym</span>
    <span class="ruby-identifier">new</span>[<span class="ruby-identifier">mime</span>]          = {}
    <span class="ruby-identifier">new</span>[<span class="ruby-identifier">mime</span>][<span class="ruby-value">:only</span>]   = <span class="ruby-identifier">only_actions</span>   <span class="ruby-keyword">unless</span> <span class="ruby-identifier">only_actions</span>.<span class="ruby-identifier">empty?</span>
    <span class="ruby-identifier">new</span>[<span class="ruby-identifier">mime</span>][<span class="ruby-value">:except</span>] = <span class="ruby-identifier">except_actions</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">except_actions</span>.<span class="ruby-identifier">empty?</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">mimes_for_respond_to</span> = <span class="ruby-identifier">new</span>.<span class="ruby-identifier">freeze</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                    </div>

    </div>
  </body>
</html>    